package com.bdzl.biz.controller;

import com.bdzl.biz.service.OrderVisitorService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.OrderVisitorDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 融资租赁订单家访员表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-11 15:02:10
 */

@Controller
@RequestMapping("/bdzl/orderVisitor")
public class OrderVisitorController extends BaseController {
	@Autowired
	private OrderVisitorService orderVisitorService;

	@GetMapping()
	String OrderVisitor(){
	    return "bdzl/orderVisitor/orderVisitor";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<OrderVisitorDO> orderVisitorList = orderVisitorService.list(query);
		int total = orderVisitorService.count(query);
		PageUtils pageUtils = new PageUtils(orderVisitorList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/orderVisitor/add";
	}

	@GetMapping("/edit/{visitorId}")
	String edit(@PathVariable("visitorId") Integer visitorId,Model model){
		OrderVisitorDO orderVisitor = orderVisitorService.get(visitorId);
		model.addAttribute("orderVisitor", orderVisitor);
	    return "bdzl/orderVisitor/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( OrderVisitorDO orderVisitor){
		if(orderVisitorService.save(orderVisitor)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( OrderVisitorDO orderVisitor){
		orderVisitorService.update(orderVisitor);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer visitorId){
		if(orderVisitorService.remove(visitorId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] visitorIds){
		orderVisitorService.batchRemove(visitorIds);
		return R.ok();
	}

}
